package com.tengju.bff.interfaces.shared.render;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenhang
 * @Date 2021/7/12
 */
@Data
public class PieVO {

    @ApiModelProperty(value = "饼图标题")
    private String title;

    @ApiModelProperty(value = "饼图数据")
    private List<PieData> pieData;

    @Data
    static class PieData {
        @ApiModelProperty(value = "标题")
        private String name;

        @ApiModelProperty(value = "数值")
        public Object value;

        public PieData(String name, Object value) {
            this.name = name;
            this.value = value;
        }
    }

    public PieVO(String title) {
        this.title = title;
    }

    public PieVO add(String name,Object val) {
        if (CollectionUtils.isEmpty(pieData)) {
            pieData = new ArrayList<>();
        }
        pieData.add(new PieData(name,val));
        return this;
    }
}
